﻿using JESAI.HttpRequestMonitor.Core.Abstracts;
using JESAI.HttpRequestMonitor.Storage.ProstgreSQL;
using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class ServiceBuildExtensions
    {
        public static IHttpRequestMonitorBuilder UsePostgreSQLStorage(this IHttpRequestMonitorBuilder builder)
        {
            builder.Services.AddOptions();
            builder.Services.Configure<PostgreStorageOptions>(builder.Configuration.GetSection("Storage"));

            return builder.UsePostgreSQLStorageService();
        }

        public static IHttpRequestMonitorBuilder UsePostgreSQLStorage(this IHttpRequestMonitorBuilder builder, Action<PostgreStorageOptions> options)
        {
            builder.Services.AddOptions();
            builder.Services.Configure<PostgreStorageOptions>(options);

            return builder.UsePostgreSQLStorageService();
        }

        internal static IHttpRequestMonitorBuilder UsePostgreSQLStorageService(this IHttpRequestMonitorBuilder builder)
        {
            builder.Services.AddSingleton<IRequestMonitorStorage, PostgreSQLStorage>();
            builder.Services.AddSingleton<PostgreConnectionFactory>();

            return builder;
        }

    }
}
